package com.qf.controller;

import com.alibaba.fastjson.JSONObject;
import com.qf.Resp.BaseResp;
import com.qf.borrower.Borrower;
import com.qf.service.RegistryService;
import com.qf.user.TbUser;
import com.qf.utils.AuthService;
import com.qf.utils.ShibieAdd;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @author H
 * @create 2020-11-03 10:54
 * @strive To be whoever you want to be.
 * @Description:
 */
@RestController
public class RegistryController {

    @Autowired
    RegistryService registryService;


    @RequestMapping("/sendCode")
    public BaseResp sendCode(@RequestBody Map map) {
        return registryService.sendCode((String) map.get("phone"));
    }

    @RequestMapping("/registry2")
    public BaseResp registry2(@RequestBody Map map) {
        String phone = (String) map.get("phone");
        Object borrower = map.get("borrower");
        String code = (String) map.get("code");
        Object o = JSONObject.toJSON(borrower);
        Borrower borrowe = JSONObject.parseObject(o.toString(), Borrower.class);
      /*  String substring = img.substring(22);
        String auth = AuthService.getAuth();

        String add = ShibieAdd.add(substring, auth, borrowe.getUsername());*/
        return registryService.registry2(borrowe, code, phone);
    }
    @RequestMapping("/addImage")
    public String addImage(@RequestParam("file")MultipartFile multipartFile,@RequestParam("username")String phone) {
       // String phone="ssssssssss";
        String auth = AuthService.getAuth();
        String add = ShibieAdd.add(multipartFile, auth,phone);
        return add;
    }
}
